package com.fulu.netty.luban.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 这个是经典的bio编程写法，记一下
 */
public class BioServer {
    public static void main(String[] args) throws IOException {
        int port = 8080;
        if(args != null && args.length > 0){
            try {
                port = Integer.parseInt(args[0]);
            } catch (NumberFormatException e) {
            }
        }
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(port);
            while (true) {
                Socket socket = serverSocket.accept();
                new Thread(new TimeServerHandler(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(serverSocket != null){
                serverSocket.close();
            }
        }
    }
}
